package com.dgh.school.service.impl;

import com.dgh.school.bean.Duty;
import com.dgh.school.bean.Schedule;
import com.dgh.school.common.R;
import com.dgh.school.mapper.ScheduleMapper;
import com.dgh.school.service.ScheduleService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ScheduleServiceImpl implements ScheduleService {


    @Autowired
    private ScheduleMapper scheduleMapper;
    @Override
    public List<Schedule> selectAll() {

        List<Schedule> schedules = scheduleMapper.selectAll();
        return schedules;
    }

    @Override
    public R selectByPage(int pageNum, int pageSize) throws Exception {

        PageHelper.startPage(pageNum, pageSize);
        // 查询全部数据
        List<Schedule> schedules = scheduleMapper.selectAll();
        // 借助分页助手，获得分页信息
        PageInfo<Schedule> pageInfo = new PageInfo<>(schedules);

        return R.ok().setDate("pageInfo", pageInfo);
    }

    @Override
    public void insertData(Schedule schedule) throws Exception {
        scheduleMapper.insertData(schedule);
    }

    @Override
    public void deleteSchedule(int id) throws Exception {
        scheduleMapper.deleteSchedule(id);
    }

    @Override
    public void updateData(Schedule schedule) throws Exception {
        scheduleMapper.updateData(schedule);
    }
}
